module.exports = {
	_before: function () { // 通用预处理器

	},
  async getInfo(page=0, size=5) {
    const db = uniCloud.database()
    // const res = await db.collection('dp').get()
    // const res = await db.collection('dp').sort({price: 0}).get()
    const res = await db.collection('dp').where({ address: new RegExp('涿州')}).get()
    // const res = await db.collection('dp').orderBy('price', 'desc').get()
    // const res = await db.collection('dp').orderBy('price asc').skip(page * size).limit(size).get()
    return res.data
  },
  async getDetail(text) {
    const db = uniCloud.database()
    const res = await db.collection('dp').where({
      address: new RegExp('涿州', 'i')
    })
    // const res = await db.collection('dp').where(`${new RegExp(text, 'i')}.test(address)`).get()
    // const res = await db.collection('goods').where(`${new RegExp(searchVal, 'i')}.test(name)`).get()
    // const res = await db.collection('dp').where({address: text}).get()
    // const res = await db.collection('dp').where({_id}).get()
    return res
  },
  async updateInfo(_id) {
    const db = uniCloud.database()
    db.collection('dp').where({_id}).update({
      price: 40,
      address: '涿州市东兴北街228号'
    })
    /* db.collection('dp').doc(_id).update({
      price: 35,
      address: '涿州市东兴北街228号'
    }) */
  },
  async addDp(form) {
    const db = uniCloud.database()
    db.collection('dp').add(form)
  },
  async deleteDp(_id) {
    const db = uniCloud.database()
    db.collection('dp').doc(_id).remove()
    // db.collection('dp').where({_id}).remove()
  }
	/**
	 * method1方法描述
	 * @param {string} param1 参数1描述
	 * @returns {object} 返回值描述
	 */
	/* 
	method1(param1) {
		// 参数校验，如无参数则不需要
		if (!param1) {
			return {
				errCode: 'PARAM_IS_NULL',
				errMsg: '参数不能为空'
			}
		}
		// 业务逻辑
		
		// 返回结果
		return {
			param1 //请根据实际需要返回值
		}
	}
	*/
}
